package com.zzj.controller;

import com.zzj.bean.UserBean;
import com.zzj.service.UserService;
import com.zzj.utils.Result;
import com.zzj.utils.VerifyCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 注册
     * @param uname
     * @param upassword
     * @param response
     * @return
     */
    @GetMapping("login")
    public Result login(String uname, String upassword, HttpServletResponse response){
        return userService.queryByUnameAndUpassword(uname, upassword,response);
    }
    @GetMapping("code")
    public String generatorCode() throws IOException {
        String s = VerifyCodeUtils.generatorCode();
        return s;
    }

    /**
     * 注册
     * @param userBean
     * @return
     */
    @PostMapping("regist")
    public Result regist(@RequestBody UserBean userBean){
        return userService.addUser(userBean);
    }
}
